package com.ihteima.controller;

import com.ihteima.pojo.Article;
import com.ihteima.pojo.PageBean;
import com.ihteima.pojo.Response;
import com.ihteima.service.ArticleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * ClassName: ArticleController
 * Package: com.ihteima.controller
 * Description:
 *
 * @Auther gongkaiming
 * @Create 2025/10/26 18:49
 * @Version 1.0
 */
@RestController
@RequestMapping("/article")
public class ArticleController {

    @Autowired
    private ArticleService articleService;

    @PostMapping
    public Response<?> add(@RequestBody @Validated Article article) {
        articleService.add(article);
        return Response.success();
    }

    @GetMapping
    public Response<PageBean<Article>> list(
            Integer pageNum,
            Integer pageSize,
            @RequestParam(required = false) Integer categoryId,
            @RequestParam(required = false) String state
    ) {
        PageBean<Article> pb = articleService.list(pageNum, pageSize, categoryId, state);
        return Response.success(pb);
    }
}
